class Solution(object):
    def numberOfArithmeticSlices(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        if n <= 2:
            return 0
        stack = [nums[0], nums[1]]
        count = 0
        for i in range(2, n):
            if nums[i] + stack[-2] == 2 * stack[-1]:
                stack.append(nums[i])
                count += len(stack) - 2
            else:
                stack = [stack[-1], nums[i]]
        return count


data = Solution()
nums = [1, 2, 3, 4]
print(data.numberOfArithmeticSlices(nums))
